package com.qf.dao.impl;

import com.qf.dao.CategoryDao;
import com.qf.pojo.Category;
import com.qf.utils.JdbcUtils;
import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanListHandler;

import java.sql.SQLException;
import java.util.List;

/**
 * @author Kuke
 * @date 2022/3/10 15:35
 * 分类的数据访问接口实现
 */
public class CategoryDaoImpl implements CategoryDao {
    /**
     * 查询所有分类列表
     * @return 返回list
     */
    @Override
    public List<Category> selectAllCategory() throws SQLException {
        //执行对象
        QueryRunner qr = new QueryRunner(JdbcUtils.getDataSource()) ;
        //sql
        String sql = "select * from category" ;
        List<Category> list = qr.query(sql, new BeanListHandler<Category>(Category.class));
        return list;
    }
}
